package com.dongdong.aspect;


import com.alibaba.fastjson.JSONObject;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.JoinPoint;
import org.aspectj.lang.Signature;
import org.aspectj.lang.annotation.*;
import org.springframework.stereotype.Component;

@Component
@Aspect
@Slf4j
public class LogAspect {


    @Pointcut("execution(* com.dongdong.service.*.*(..))||@annotation(LogAn)")
    public void log(){}


    @Before("log()")//前置通知
    public void beforeAspect(JoinPoint joinPoint){
//        参数
        Object[] args = joinPoint.getArgs();
//        方法名
        Signature signature = joinPoint.getSignature();
        log.info("方法名:{},参数:{}",signature,args);
    }

//    返回后通知
    @AfterReturning(value = "log()",returning = "after")
    public void afterAspect(Object after){
        String s = JSONObject.toJSONString(after);
        log.info("返会后数据:{}",s);
    }

}
